home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Applications / Eudora 1.3.1 / source / shame.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-16  |  7.8 KB  |  281 lines  |  [TEXT/MPS ]

  1. #define FILE_NUM 35
  2. /* Copyright (c) 1990-1992 by the University of Illinois Board of Trustees */
  3. /**********************************************************************
  4.  * functions of which I am not proud
  5.  **********************************************************************/
  6. #pragma load EUDORA_LOAD
  7. #pragma segment Util
  8. static Boolean AlertBeep=True;
  9. void DeepTrouble(UPtr);
  10. void SilenceAlert(int template);
  11. void TrashAlert(int template);
  12. short AlertDefault(short template);
  13. #define GetANumber() (*(short *)0xa98)
  14. /************************************************************************
  15.  *
  16.  ************************************************************************/
  17. int Aprintf(short template,short which,short rFormat,...)
  18. {
  19.     Str255 message;
  20.     va_list args;
  21.     va_start(args,rFormat);
  22.     VaComposeRString(message,rFormat,args);
  23.     va_end(args);
  24.     return(AlertStr(template,which,message));
  25. }
  26.     
  27. /************************************************************************
  28.  *
  29.  ************************************************************************/
  30. int AlertStr(int template, int which, UPtr str)
  31. {
  32.     MyParamText(str,"","","");
  33.     return(ReallyDoAnAlert(template,which));
  34. }
  35.  
  36. /**********************************************************************
  37.  * print an alert
  38.  **********************************************************************/
  39. int ReallyDoAnAlert(int template,int which)
  40. {
  41.     int item;
  42.     
  43.     LogAlert(template);
  44.     if (!MommyMommy(ATTENTION,nil))
  45.       item = AlertDefault(template);
  46.     else
  47.     {
  48.         WNE(nil,nil,0);                             /* make sure InBG is right */
  49.         PushCursor(arrowCursor);
  50.         ThirdCenterDialog(template);
  51.         if (!AlertBeep) SilenceAlert(template);
  52.         if (AlertsTimeout && AlertTicks < TickCount())
  53.             AlertTicks=GetRLong(ALERT_TIMEOUT)*60+TickCount();
  54.         switch (which)
  55.         {
  56.             case Normal:    item = Alert(template,DlgFilter); break;
  57.             case Stop:        item = StopAlert(template,DlgFilter); break;
  58.             case Note:        item = NoteAlert(template,DlgFilter); break;
  59.             case Caution: item = CautionAlert(template,DlgFilter); break; 
  60.         }
  61.         if (!AlertBeep) TrashAlert(template);
  62.         AlertTicks = 0;
  63.     }
  64.     ComposeLogR(LOG_ALRT,nil,ALERT_DISMISSED_ITEM,item);
  65.     PopCursor();
  66.     return(item);
  67. }
  68.  
  69. /************************************************************************
  70.  * AlertDefault - find the default action for an alert
  71.  ************************************************************************/
  72. short AlertDefault(short template)
  73. {
  74.     AlertTHndl alert=GetResource('ALRT',template);
  75.     short item=1;
  76.     short stage;
  77.     if (alert)
  78.     {
  79.         stage = (template==GetANumber()) ? GetAlrtStage() : 0;
  80.         stage = MIN(3,stage);
  81.         GetAlrtStage() = MIN(stage+2,4);
  82.         GetANumber() = template;
  83.         item = ((*alert)->stages&(8<<(stage*4))) ? 2 : 1;
  84.     }
  85.     return(item);
  86. }
  87.  
  88. /**********************************************************************
  89.  * DeepTrouble - tell the user that BAD things are happening
  90.  **********************************************************************/
  91. void DeepTrouble(str)
  92. UPtr str;
  93. {
  94.     MyParamText(str,"","","");
  95.     InitCursor();
  96.     CenterDialog(OK_ALRT);
  97.     (void) StopAlert(OK_ALRT,nil);
  98.     ExitToShell();
  99. }
  100.  
  101. /************************************************************************
  102.  * IsSwitch - is a mouseDown in the MF switch area?
  103.  ************************************************************************/
  104. Boolean IsSwitch(EventRecord *event)
  105. {
  106.     Rect bnds = qd.screenBits.bounds;
  107.     bnds.bottom = bnds.top+GetMBarHeight();
  108.     bnds.left = bnds.right-36;
  109.     return (PtInRect(event->where,&bnds));
  110. }
  111.  
  112. /************************************************************************
  113.  * Switch - go to the next MF app
  114.  ************************************************************************/
  115. Boolean Switch(void)
  116. {
  117.     Str63 name, appName;
  118.     short appRefNum;
  119.     Handle apParam;
  120.     short barItem, item, myItem, n, cmd;
  121.     MenuHandle appM = GetMHandle(APPLE_MENU);
  122.     long resp;
  123.     
  124.     if (!Gestalt(gestaltOSAttr,&resp) && resp&(1L<<gestaltLaunchControl))
  125.     {
  126.         Point pt;
  127.         pt.h = qd.screenBits.bounds.right-30; pt.v = 10;
  128.     
  129.         return(MenuSelect(pt));
  130.     }
  131.  
  132.     GetAppParms(appName,&appRefNum,&apParam);
  133.     
  134.     n = CountMItems(appM);
  135.     
  136.     for (item=2;item<n;item++)
  137.     {
  138.         GetItem(appM,item,name);
  139.         if (name[1]=='-') barItem=item;
  140.         else if (EqualString(name,appName,False,True))
  141.         {
  142.             myItem = item;
  143.             break;
  144.         }
  145.     }
  146.     
  147.     if (item>n) return(False);                                        /* not found */
  148.     if (item==n)
  149.         if (barItem==item-1) return(False);                 /* nobody else */
  150.         else item=barItem;                                                    /* bottom of menu */
  151.     else
  152.     {
  153.         GetItem(appM,item+1,name);
  154.         if (name[1]=='-')
  155.             if (barItem==item-1)
  156.                 return(False);                                                    /* nobody else */
  157.             else
  158.                 item=barItem;                                                     /* bottom of app list */
  159.     }
  160.     
  161.     for (item++;item!=myItem;item++)
  162.         if (item>n) item=barItem;
  163.         else
  164.         {
  165.             GetItem(appM,item,name);
  166.             if (name[1]=='-') item=barItem;
  167.             else
  168.             {
  169.                 GetItemCmd(appM,item,&cmd);         /* undocumented magic here */
  170.                 if (cmd!=0x1f)                                    /* is the app not hidden? */
  171.                 {
  172.                     OpenDeskAcc(name);
  173.                     return(True);
  174.                 }
  175.             }
  176.         }
  177.  
  178.     return(False);
  179.  
  180. /************************************************************************
  181.  * SetAlertBeep - set whether or not an alert should beep
  182.  ************************************************************************/
  183. void SetAlertBeep(Boolean onOrOff)
  184. {
  185.     AlertBeep = onOrOff;
  186. }
  187.  
  188. /************************************************************************
  189.  * SilenceAlert - turn the beeps off in an alert template
  190.  ************************************************************************/
  191. void SilenceAlert(int template)
  192. {
  193.     AlertTHndl aTempl;
  194.  
  195.     if (aTempl=(AlertTHndl)GetResource('ALRT',template))
  196.         (*aTempl)->stages &= ~0x3333;
  197. }
  198.  
  199. /************************************************************************
  200.  * TrashAlert - get rid of a mucked alert template
  201.  ************************************************************************/
  202. void TrashAlert(int template)
  203. {
  204.     AlertTHndl aTempl;
  205.  
  206.     if (aTempl=(AlertTHndl)GetResource('ALRT',template))
  207.         ReleaseResource(aTempl);
  208. }
  209.  
  210. pascal void OkWhatIsIt(QElemPtr nmReqPtr);
  211.  
  212. /************************************************************************
  213.  * MommyMommy - get the user's attention
  214.  ************************************************************************/
  215. Boolean MommyMommy(short sId,UPtr string)
  216. {
  217.     NMRec nm;
  218.     Str255 scratch;
  219.     short pend;
  220.     short nmResult;
  221.     
  222.     if (!InBG) return(True);
  223.     WriteZero(&nm,sizeof(nm));
  224.     
  225.     nm.nmSound = PrefIsSet(PREF_NEW_SOUND) ? GetResource('snd ',ATTENTION_SND):nil;
  226.     nm.nmResp = OkWhatIsIt;
  227.     nm.nmStr = PrefIsSet(PREF_NEW_ALERT) ? (string ? string : (sId ? GetRString(scratch,sId) : nil)) : nil;
  228.     nm.nmRefCon = (long) &pend;
  229.     nm.nmMark = 1;
  230.     nm.nmIcon = PrefIsSet(PREF_NO_APPLE_FLASH) ? nil : GetResource('SICN',EUDORA_SICN);
  231.     nm.qType = nmType;
  232.     if (nm.nmSound) HNoPurge(nm.nmSound);
  233.     if (nm.nmIcon) HNoPurge(nm.nmIcon);
  234.     nmResult = NMInstall(&nm);
  235.     if (pend!=inProgress)
  236.         pend=SpinOn(&InBG,AlertsTimeout?GetRLong(ALERT_TIMEOUT)*60:0);
  237.     if (!nmResult) NMRemove(&nm);
  238.     return(pend==0);
  239. }
  240.  
  241. #pragma segment Main
  242. /************************************************************************
  243.  *
  244.  ************************************************************************/
  245. pascal void OkWhatIsIt(QElemPtr nmReqPtr)
  246. {
  247.     *(short *)((NMRec *)nmReqPtr)->nmRefCon = 0;
  248. }
  249. #pragma segment Util
  250.  
  251. #ifdef DEBUG
  252. #define TRIGGER (28<size && size < 54)
  253. /************************************************************************
  254.  *
  255.  ************************************************************************/
  256. UPtr NuPtr(long size)
  257. {
  258.     if (BUG8 && TRIGGER) SysBreak();
  259.     return(NewPtr(size));
  260. }
  261.  
  262. /************************************************************************
  263.  *
  264.  ************************************************************************/
  265. Handle NuHandle(long size)
  266. {
  267.     if (BUG8 && TRIGGER) SysBreak();
  268.     return(NewHandle(size));
  269. }
  270.  
  271. /************************************************************************
  272.  *
  273.  ************************************************************************/
  274. void SetHandleBig(Handle h,long size)
  275. {
  276.     if (BUG8 && TRIGGER) SysBreak();
  277.     SetHandleSize(h,size);
  278. }
  279. #endif
  280.